﻿<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>场馆地址</title>
        <script src="js/jquery-3.2.1.min.js"></script>
        <script src="js/common.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3GIvXq4SkW3XwdbEjae5ghEAs8reia4Y"></script>

  <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>

</head>

<body>
   <div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
var xPoint = $.getParam("xPoint");
var yPoint = $.getParam("yPoint");
var newxPoint = "";
var newyPoint = "";
var city = "";

    var map = new BMap.Map("allmap");
    var point = new BMap.Point(116.709684,39.89778);
    map.centerAndZoom(point, 16);
    map.enableScrollWheelZoom();

    var myIcon = new BMap.Icon("myicon.png",new BMap.Size(30,30),{
        anchor: new BMap.Size(10,10)
    });

    var marker=new BMap.Marker(point,{icon: myIcon});
    map.addOverlay(marker);

    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            $('#AdressIP').val(r.point.lng + ',' + r.point.lat);
            newxPoint = r.point.lng;
            newyPoint = r.point.lat;
            //alert('您的位置：' + r.point.lng + ',' + r.point.lat);
            var gc = new BMap.Geocoder();
            var pt = r.point;
            gc.getLocation(pt, function (rs) {
                var addComp = rs.addressComponents;
                address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
                city = addComp.city;
                //点击后在地图显示地理位置
                //var label = new BMap.Label(address, { offset: new BMap.Size(20, -10) });
                //$('#Adress').val(address);

                //alert(city);
    //console.log("origin="+newyPoint+","+newxPoint+"&destination="+yPoint+","+xPoint+"&mode=driving&region="+city+"&output=html");
    var newIframeObject=document.createElement("IFRAME");
                    newIframeObject.src="http://api.map.baidu.com/direction?origin="+newyPoint+","+newxPoint+"&destination="+yPoint+","+xPoint+"&mode=driving&region="+city+"&output=html";
                    newIframeObject.scrolling="no";
                    newIframeObject.frameBorder=0;
                    newIframeObject.width="100%";
                    newIframeObject.height="100%";
            $("#allmap").html(newIframeObject);
                //location.href="http://api.map.baidu.com/direction?origin="+newyPoint+","+newxPoint+"&destination="+yPoint+","+xPoint+"&mode=driving&region="+city+"&output=html";
            });
        }
        else {
            alert('failed' + this.getStatus());
        }
    }, { enableHighAccuracy: true });

</script>
